import Taro, { Component } from '@tarojs/taro'
import { View, Text, RichText, Image } from '@tarojs/components'

import {localTime} from '../../utils/date'
import './index.scss'

class TopicInfoContent extends Component{
  editTopicDetail(info){
    Taro.redirectTo({url: '/pages/public/index?edit=1'})
  }
  render(){
    let {info, selfPublic} = this.props
    return(
      <View className='topic-info'>
        <View className='topic-info-header'>
          <View className='topic-info-header-title'>
          {info.top ? <Text className='topic-up'>置顶</Text> : (info.tab === 'share' ? <Text className='topic-up blue'>分享</Text> : <Text className='topic-up blue'>问答</Text>)}
            <Text>{info.title}</Text>
          </View>
          <View className='topic-info-header-item'>
            <Text>发布时间{localTime(info.create_at)}</Text>
            <Text>{info.author.loginname ? info.author.loginname : ''}</Text>
            <Text>{info.visit_count}次浏览</Text>
          </View>
          {
            selfPublic ? (
            <View className='control-topic'>
              <Image className='control-topic-img' src={require('../../assets/images/delete.png')} />
              <Image onClick={this.editTopicDetail.bind(this, info)} className='control-topic-img' src={require('../../assets/images/edit.png')} />
            </View>) : null
          }
        </View>
        <View className='topic-info-content'>
          <RichText nodes={info.content} />
        </View>
      </View>
    )
  }
}

TopicInfoContent.defaultProps = {
  info: {}
}

export default TopicInfoContent